﻿using System;
using Sundstrom.Validation;

namespace Sundstrom.Mvvm.Validation
{
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false)]
    public sealed class ExpectInt32Attribute : ValidationAttribute
    {
        public ExpectInt32Attribute()
        {
            ErrorMessage = "Expected an integer value.";
        }

        public override ValidationResult Validate(object value, ValidationContext validationContext)
        {
            return value is int ? null : new ValidationResult(ErrorMessage, validationContext.MemberName);
        }
    }
}